package com.school.service.impl;

import com.school.dao.StudentDao;
import com.school.dao.impl.StudentDaoImpl;
import com.school.model.Student;
import com.school.service.StudentService;

import java.util.Collection;
import java.util.List;

/**
 * 复杂功能的包装，对数据单元操作进行组装实现复杂功能
 */
public class StudentServiceImpl implements StudentService {

    private StudentDao studentDao = new StudentDaoImpl();

    @Override
    public Student insert(Student student) {
        return studentDao.insert(student);
    }

    @Override
    public List<Student> insert(List<Student> students) {
        return studentDao.insert(students);
    }

    @Override
    public void delete(Integer id) {
        studentDao.delete(id);
    }

    @Override
    public void delete(Collection<Integer> ids) {
        studentDao.delete(ids);
    }

    @Override
    public void update(Student student) {
        studentDao.update(student);
    }

    @Override
    public void update(List<Student> students) {
        studentDao.update(students);
    }

    @Override
    public int count() {
        return studentDao.count();
    }

    @Override
    public Student findOneById(Integer id) {
        return studentDao.findOneById(id);
    }

    @Override
    public List<Student> findPage(Student student, Integer page, Integer size) {
        // page : 当前页数 5 ，10    0，1，2，3，4
        int offset = (page - 1) * size;
        return studentDao.findPage(student, offset, size);
    }
}
